-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entity Relations #1627
Entity Relations #1627
Conversation
58bc666
to
75062f3
Compare
d41a88f
to
213882c
Compare
Future work after this PR: think about how relations should work with scenes |
With the last commit this test now passes: #[test]
fn query() {
struct ChildOf;
let mut world = World::new();
let parent1 = world.spawn().id();
let child1 = world.spawn().insert_relation(ChildOf, parent1).id();
let parent2 = world.spawn().id();
let child2 = world.spawn().insert_relation(ChildOf, parent2).id();
let mut query = world.query::<(Entity, &Relation<ChildOf>)>();
let mut iter = query.iter_mut(&mut world);
assert!(iter.next() == Some((child1, ())));
assert!(iter.next() == Some((child2, ())));
assert!(iter.next() == None);
query.set_relation_filter(
&world,
QueryRelationFilter::new().add_target_filter::<ChildOf, _>(parent1),
);
let mut iter = query.iter_mut(&mut world);
assert!(iter.next() == Some((child1, ())));
assert!(iter.next() == None);
query.set_relation_filter(
&world,
QueryRelationFilter::new().add_target_filter::<ChildOf, _>(parent2),
);
let mut iter = query.iter_mut(&mut world);
assert!(iter.next() == Some((child2, ())));
assert!(iter.next() == None);
} Still a lot of work to do but it's nice to see something working :O |
9fecf62
to
d0e5401
Compare
Would you have an abstract for the overall approach to your implementation? |
These sort of design details are important to communicate clearly, and Boxy and I are aiming to write up the RFC mentioned in this PR's title Soon:tm: <3 This will be hard to review until then (and is deliberately a draft PR). |
59ed501
to
13b82b4
Compare
df474ad
to
d35d9b9
Compare
crates/bevy_ecs/src/archetype.rs
Outdated
sparse_set_components: Cow<'static, [ComponentId]>, | ||
pub(crate) unique_components: SparseSet<ComponentId, Column>, | ||
pub(crate) components: SparseSet<ComponentId, ArchetypeComponentInfo>, | ||
table_components: Cow<'static, [(RelationKindId, Option<Entity>)]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Entity
should get a niche by for example making generation
a NonZeroU32
. This would make Option<Entity>
just as big as Entity
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually want to remove all the Option<Entity>
everywhere and just have a dedicated entity for the None
case as it'll make a lot of the API nicer. It's kind of annoying to have to return or take Option<Entity>
in places where 99% of the time it will be Some(..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example when setting the target filters on a Relation query param we currently just take an Entity
but really we ought to be taking an Option<Entity>
. Problem then is 99% of use cases have to wrap it in Some just because someone might want to query for the None
case...
I could take some T: Into<Option<Entity>>
for that specific function but there are other places where this kind of pattern doesnt work, like the return type of the RelationAccess<T>
iterator that returns the target entity- except the target Entity should actually be Option<Entity>
but if I did that you'd either be unwrapping or doing a bunch of boilerplate to handle the None
case :S
9c6550d
to
ee94150
Compare
73fd66e
to
b768f5e
Compare
a270339
to
611894a
Compare
|
75f40d0
to
72e0efa
Compare
db347a5
to
5c6f5fe
Compare
8ea24cc
to
b7172d7
Compare
Co-authored-by: Patrik Buhring <patrikbuhring@gmail.com>
b7172d7
to
48183c6
Compare
RFC
warning: this PR does not implement all of the RFC and some of the RFC is out of date
cc #1527 #1592 #142